package cur.nature.log.controller;

import cur.nature.framework.core.util.StringUtil;
import cur.nature.log.model.Log_CommonVO;
import cur.nature.log.service.Log_CommonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询日志数据 Controller
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 16:14:19
 */
@Tag(name = "日志 接口")
@RestController
@RequestMapping("component/log/v1/api")
@ConditionalOnProperty( value = {"cur.component.log.controller.enable"})
public class Log_CommonController {

    @Autowired
    private Log_CommonService log_CommonService;

    @Operation(summary = "查询日志数据")
    @PostMapping("/list")
    public List<Log_CommonVO.list_Res> list(@RequestBody Log_CommonVO.list_Param param) throws Exception {
        if (StringUtil.isEmpty(param.getTraceId())) {
            Log_CommonVO.list_Res tmp = new Log_CommonVO.list_Res();
            tmp.setLog(Arrays.asList("请输入 trace_id"));
            return Arrays.asList(tmp);
        }
        final List<Log_CommonVO.list_Res> log = log_CommonService.queryByTraceId(param);
        return log;
    }

    @Operation(summary = "下载日志数据")
    @GetMapping("/download")
    public String download(HttpServletResponse response) throws IOException {
        return log_CommonService.download(response);
    }



}

